CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
PROJECT(CppRt)
MESSAGE("---- CMAKE_SOURCE_DIR = ${CMAKE_SOURCE_DIR}")
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}")
INCLUDE(doc)


SET(PREFIX ${CMAKE_INSTALL_PREFIX})
SET(EXEC_PREFIX "\${prefix}")
SET(LIBDIR ${PREFIX}/lib)
SET(INCLUDEDIR ${PREFIX}/include)
SET(VERSION_MAJOR 0)
SET(VERSION "${VERSION_MAJOR}.0.1")
#SET(LIBDIR_INST ${PREFIX}/lib)
SET(C_PREFIX ${PREFIX})
SET(SRCS ${CMAKE_SOURCE_DIR}/src/cpprt.cpp) 
include_directories(${CppRt_SOURCE_DIR}/inc ${CppRt_SOURCE_DIR}/src)
link_directories(${CppRt_BINARY_DIR}/src)


SET(CMAKE_CXX_FLAGS_DEBUG "-fPIC  -O0  -Wall -c")
SET(CMAKE_CXX_FLAGS_RELEASE "{$CMAKE_C_FLAGS_DEBUG} -g -DDEBUG")
 
IF(DEFINED USE_SET_ERRNO_INTERNAL)
ADD_DEFINITIONS (-DSET_ERRNO_INTERNAL=1 )
ENDIF(DEFINED USE_SET_ERRNO_INTERNAL)


ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS})
SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES COMPILE_FLAGS "${CMAKE_C_FLAGS} -I${CMAKE_SOURCE_DIR}/include")
SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES SOVERSION ${VERSION_MAJOR})
SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES VERSION ${VERSION})

SET(PC_PREFIX ${PREFIX})
SET(PC_VERSION ${VERSION})
CONFIGURE_FILE(${PROJECT_NAME}.pc.in ${PROJECT_NAME}.pc @ONLY)
SET_DIRECTORY_PROPERTIES(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${PROJECT_NAME}.pc")

INSTALL(TARGETS ${PROJECT_NAME} DESTINATION lib)
INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc DESTINATION lib/pkgconfig)
INSTALL(FILES ${CMAKE_SOURCE_DIR}/inc/cpprt.h DESTINATION ${INCLUDEDIR})